package com.yanxu;

/**
 * @author 折戟沉沙铁未销
 * @version V1.0
 * @date 2024/11/13-2024
 * @Description: 这里用一句话描述这个类的作用
 */
public class DaemonThread {

    public static void main(String[] args) {
        Thread thread1 = new Thread(new Runnable() {
            public void run() {
                System.out.println("子线程执行任务逻辑!!!");
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("子线程执行任务逻辑完毕!!!");
            }
        });
        thread1.setDaemon(true);  //因为将子线程 thread1 设置成了守护线程，所以main线程执行完毕后，jvm 直接关闭了， thread1中的逻辑根本执行不完。
        thread1.start();
        System.out.println("main 线程执行逻辑!!!");
    }


    public static void main1(String[] args) {
        Thread thread1 = new Thread(new Runnable() {
            public void run() {
                System.out.println("子线程执行任务逻辑!!!");
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("子线程执行任务逻辑完毕!!!");
            }
        });

        thread1.start();
        System.out.println("main 线程执行逻辑!!!");
    }
}